<?php
/**
 * Created by PhpStorm.
 * User: HP
 * Date: 2021/6/8
 * Time: 9:25
 */

namespace app\common\model;

use think\Model;
class Listing extends Model
{
    //  连接数据库
    protected $connection = 'hospital';
   //  自动写入时间戳字段
    protected $createTime = 'created_at';
    protected $updateTime = 'updated_at';

    // 关联 classify
    public function classify()
    {
        return $this->hasOne(Classify::class, 'id', 'classify_id')
            ->field('id,title');
    }

    //  根据id获取用户信息
    public function fetchInfoById($id, $field = '*')
    {
        return $this->field($field)->find($id);
    }

    //  根据where条件查询用户信息
    public function fetchInfoByWhere($where, $field = ['*'])
    {
        return $this->where($where)->field($field)->find();
    }
}